const mongoose = require("mongoose");
var Order = mongoose.model("order");
var Merchant = mongoose.model("merchant");

exports.findAllOrder = function(req, res) {
    Order.find(function(err, orders) {
        res.json(orders)
    });
}



exports.rejectStatus = function(req, res) {
    Order.findOne({ oId: req.params.oId }, function(err, order) {
        console.log(order);
        order.oStatus = 2;
        order.save(function(err) {
            if (err) { res.send("fail"); } else { res.send("success") }
        })
    });

}
exports.deductStatus = function(req, res) {
    Order.findOne({ oId: req.params.oId }, function(err, order) {
        console.log(order);
        order.oStatus = 3;
        order.save(function(err) {
            if (err) { res.send("fail"); } else { res.send("success") }
        })
    });

}
exports.blackStatus = function(req, res) {
    Order.findOne({ oId: req.params.oId }, function(err, order) {
        console.log(order);
        order.oStatus = 4;
        order.save(function(err) {
            if (err) { res.send("fail"); } else { res.send("success") }
        })
    });
    Merchant.findOne({ mId: req.params.mId }, function(err, merchant) {
        merchant.mStatus = 4;
        merchant.save(function(err) {
            if (err) { res.send("fail"); } else { res.send("success") }
        });
    });

}
exports.showOrderStatusWS=function(req,res){
    Order.findOne({oId:req.params.oId},function(err,order){
        console.log("order.oStatus...."+order.oStatus);
        res.send(order.oStatus+"");
    })
}